package com.example.shopdemo.repository;

import com.example.shopdemo.entity.ProductCategory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ：Anitaxiaofeng
 * @description：
 * @create 2018-01-21
 **/
public interface ProductCategoryRepository extends JpaRepository<ProductCategory,Long> {
    List<ProductCategory> findByShopIdOrderByPriorityDesc(Long shopId);

    @Transactional
    @Modifying
    @Query(value = "delete from product_category where product_category_id = :productCategoryId and shop_id=:shopId",nativeQuery = true)
    void deleteByProductCategoryIdAndShopId(@Param("productCategoryId")Long productCategoryId,
                                            @Param("shopId")Long shopId);

}
